﻿define('ui/controller/yearController',
	['ui/controller/conditionController'],
	function(conditionController) {

	var yearController = {
			
		initial: function(){
			$("em.cl-year>span").first().text('年份');
			
			yearController.render(5);
		},
		
		render: function(diff){
			
			var d = new Date().getFullYear();
			var html = '';
			for(var i=0; i<diff; i++){
				html +='<li id="cl-'+i+'" class="" data-val="business_year_flag=1;adcode='+(d-i)+';custom=business_year:'+(d-i)+'年">'+
								'<span class="cl-area-name">'+
								(d-i)+'年'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'
			}
			html = '<ul class="classify-sort-type">'+ html +'</ul>';
			$("#year").html(html); 
			$('#year ul.classify-sort-type li').first().addClass('sort-select');
			
			yearController.onMove();
			yearController.onSelect();
		},
		
		onMove: function() {
			$('#year ul.classify-sort-type li').each(function(){
				$(this).mouseover(function(){
					$('ul.classify-sort-type li').removeClass('sort-select');
					$(this).addClass('sort-select');
				});
			});
		},
		
		onSelect: function() {
			$('#year ul.classify-sort-type li').each(function(){
				$(this).click(function(){
					var val = $(this).attr('data-val');
					var s = val.split(";")
					var $span = $("em.cl-year>span").first();
					$span.text($(this).text());
					$('#year ul.classify-sort-type li').removeClass('sort-select');
					$(this).addClass('sort-select');
					conditionController.hideConditionList();
					
					yearController.setYearCode($span, s[1].split("=")[1]?s[1].split("=")[1]:'');
					
					//todo：LMarkerList
					var licenseML = require('ui/markerList/licenseML');
					licenseML.reRenderData();
				});
			});
		},
		
		setYearCode:function($span, code){
			$span.attr('data-spm-anchor-id', code);
		},
		
		getYearCode:function(){
			var $span =$("em.cl-year>span").first();
			return $span.attr('data-spm-anchor-id');
		}
	};
	
	return yearController;
});